<?php
include "include/config.inc.php";
if(!isset($_SESSION['s_activId']))
{
  header('location:checkLogin.php');
}
$today = date('Y-m-d');  
//$startDate = date('2001-01-01','Y-m-d');  

 // echo $toDate         = $_POST['toDateYear']."-".$_POST['toDateMonth']."-".$_POST['toDateDay'];
  $fromDate       = '2001-01-01';
  $totalAmount    = "SELECT SUM(pendingAmount) AS totalAmount
                       FROM loan
                      WHERE  loanDate BETWEEN '".$fromDate."' 
                             AND '".$today."'";
  $totalAmountRes = mysql_query($totalAmount);
  $totalAmountRow = mysql_fetch_array($totalAmountRes);
  
  //Total Interest Process
  $totalInterest    = "SELECT SUM(amount) AS totalInterest
                         FROM rojmel
                        WHERE accountId = 2";
  $totalInterestRes = mysql_query($totalInterest);
  $totalInterestRow = mysql_fetch_array($totalInterestRes);

if(isset($_POST['dateSubmit']))
{
  //Total Amount Process
  $toDate         = $_POST['toDateYear']."-".$_POST['toDateMonth']."-".$_POST['toDateDay'];
  $totalAmount    = "SELECT SUM(pendingAmount) AS totalAmount
                       FROM loan
                      WHERE loanDate >= ".$toDate;
  $totalAmountRes = mysql_query($totalAmount);
  $totalAmountRow = mysql_fetch_array($totalAmountRes);
  
  //Total Interest Process
  $totalInterest    = "SELECT SUM(amount) AS totalInterest
                         FROM rojmel
                        WHERE accountId = 2";
  $totalInterestRes = mysql_query($totalInterest);
  $totalInterestRow = mysql_fetch_array($totalInterestRes);
}

include("bottom.php");
$smarty-> assign("today", $today);
//$smarty-> assign("startDate", $startDate);
$smarty-> assign("totalAmountRow", $totalAmountRow);
$smarty-> assign("totalInterestRow", $totalInterestRow);
$smarty->display('totalLoan.tpl');  
?>